Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

116
Vistas
regex capture content of {} only if no part is inside "" (and other encapsulators)

are regular expressions even appropriate for this problem? I'm trying to extract blocks of text surrounded by 'raw' curly braces. so anything surrounded by "" or **,"",~~,``, should be ignored entirely. sample text:

{
"text1"
'text2'
*text3*
~text4~
`text5`
}
{
"half  broken1}{"
*half  broken2}{*
'half  broken3}{'
~half  broken4}{~
`half  broken5}{`
}
{
"{nested text1}"
'{nested text2}'
~{nested text3}~
*{nested text4}*
`{nested text5}`
}
{
"text1"
{
`text2`
}
}

expected output:

[
"\"text1\"
'text2'
*text3*
~text4~
`text5`",

"\"half  broken1}{\"
*half  broken2}{*
'half  broken3}{'
~half  broken4}{~
`half  broken5}{`",

"\"{nested text1}\"
'{nested text2}'
~{nested text3}~
*{nested text4}*
`{nested text5}`",

"\"text1\"
{
`text2`
}",
"`text2`"
]

I can target curly braces with:

/(?<=\{)[^}]*(?=\})/gm

but that eats the first } facing brace it finds to match. I have tried a few other strings, but so far - I don't know how to ignore {"}"} the first brace in this case.

(using js syntax for regex)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

https://regex101.com/r/EODDXL/1

(?<=\{)(?:"[^"]*"|'[^']*'|\*[^*]*\*|~[^~]*~|`[^`]*`|{[^}]*}|[^}])*?(?=\})

That's starting with what you had, but includes ignoring " followed by 0 or more [^"] followed by a ". Then repeat this pattern for ', *, ~, ` and {}. This captures the outer groups only. I'm not sure how exactly you'd get the expected output at the end, but this may get you in the right direction.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda